<?php
/**
 * 根据不同类型显示广告列表
 * 使用方法
 * 按分类：  
 * {:W('Ad',array('position'=>'0','pic'=>'1','listRows'=>'5','tpl'=>'index'))}
 * @author 林吉 <317365887@qq.com>
 */
class AdWidget extends Widget {
    public function render($data) 
    {
        $data['listRows']=isset($data['listRows'])?$data['listRows']:5;
        $data['tpl']=isset($data['tpl'])?$data['tpl']:'index';
        $ad=M('Ad');
        if(isset($data['position']))$where['position_id']=$data['position'];
        if(isset($data['pic']))$where['pic']=array('neq','');
        $now=time();
        $where['start_time']=array('lt',$now);
        $where['end_time']=array('gt',$now);
        $where['status']=1;
        $data['data']=$ad->field('title,url,pic')->where($where)->select();
        $html = $this->renderFile($data['tpl'],$data);
        return $html;
    }
}
?>